package com.ku6.dao;

import org.hibernate.Session;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.jboss.seam.annotations.In;

import com.ku6.common.base.PageCodeBase;
import com.ku6.common.util.Helper;
//import com.ku6.user.User;

/**
 * 2008-8-8
 * 
 * @author daniel zhang
 * 
 */
public class DAOBase extends PageCodeBase {

	@In(value = "ku6DB", required = false)
	public Session em;

	public FullTextSession getFullTextSession() {
		FullTextSession fts = null;
		try {
			fts = (FullTextSession) em;
		} catch (Exception ex) {
			fts = Search.createFullTextSession(em);
		}
		return fts;
	}

	public Session getHibernateSession() {
		return em;
	}

	public DAOBase() {
		if (em == null) {
			em = Helper.getInstance().getSession();
		}
	}

	/*public User getCurrentUser() {
		User currentUser = new User();
		try {
			if (null != this.getSessionScope().get("loginUser")) {
				currentUser = (User) this.getSessionScope().get("loginUser");
			} else {
				currentUser = new User();// avoid throw exception for test
				currentUser.setNickName("匿名用户");
			}

		} catch (Exception ex) {
			this.logException(ex);
		}
		return currentUser;
	}

	public void setCurrentUserToSession(User user) {
		this.getSessionScope().put("loginUser", user);
	}

	public void removeCurrentUser() {
		this.getSessionScope().remove("loginUser");
	}*/

	public String addRedColor(String string) {
		return "<font color=red>" + string + "</font>";
	}
}
